﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

// 豌豆射手
public class PeaShooter : PlantInScene
{
    Timer _attackTimer;

    protected override void onGrow(Grid grid)
    {
        base.onGrow(grid);

        _skillLine.AddEvent(0, 10, onPlayAni);
        _skillLine.AddEvent(0.726f, 1, onFlyObject);
        _skillLine.AddEvent(0.857f, 10, onEndAni);

        _attackTimer = TimerMgr.instance.CreateTimerAndStart(3, -1, checkAndAttack);
    }

    // 生成子弹
    private void onFlyObject(int flyObjID)
    {
        var obj = ResMgr.instance.InstanceGameObject("FightScene/Bullet/PeaBullet", _modelRoot.Find("ShootPoint").position);

        var flyObj = obj.AddComponent<FlyObject>();
        flyObj.Owner = this;
        flyObj.DefautDirection = _modelRoot.right;
        //flyObj.HitCallback = onHitZombie;
        //flyObj.MaxFlyDistance = 
    }

    protected override void onKilled()
    {
        base.onKilled();
        _attackTimer.Stop();
    }

    // 检查并攻击
    private void checkAndAttack()
    {
        if (_curGird.AttackLine.HasZombie)
        {
            // 还要判断僵尸在我的前方
            attackOnce();
        }
    }

    private void attackOnce()
    {
        _skillLine.Start();
    }
}

